﻿using Model;
using System;
using System.Collections.Generic;
using System.Data;
using Utility.Helper;

namespace BLL
{
    public class BankBillsLedgerBLL : BaseBLL
    {
        public DataTable GetListByPage(string whereStr, string orderby, int startIndex, int endIndex)
        {
            string sql = string.Format(@"SELECT *
  FROM (SELECT ROW_NUMBER() OVER(ORDER BY " + orderby + @") as r,
               CMY.CMY_NAME AS CMY_NAME,
               BANK.C_NAME AS C_NAME,
               DECODE(T1.TYPE,
                      1,
                      '商业汇票',
                      2,
                      '银行本票',
                      3,
                      '转账支票',
                      4,
                      '现金支票') as TYPENAME,
               T1.*,
               T2.*,
               T3.USER_NAME AS USER_NAME
          FROM ((SELECT 1                         AS TYPE,
                        N_TRADEBILL_ID            AS ID,
                        N_TRADEBILL_DRAWERCMYID   AS DE_COMPANY_ID,
                        N_TRADEBILL_DRAWERBANKID  AS DE_BANK_ID,
                        C_TRADEBILL_DRAWERACCOUNT AS ACCOUNT,
                        C_TRADEBILL_PAYEENAME     AS PAYEENAME,
                        D_TRADEBILL_STARTDATE     AS START_DATE,
                        N_TRADEBILL_INVOICEVALUE  AS PAY_AMOUNT,
                        C_TRADEBILL_CODE          AS DE_CODE,
                        C_TRADEBILL_REMARK        AS REMARK
                   FROM yx_tradebill) UNION
                (SELECT 2                         AS TYPE,
                        N_BANKCHECK_ID            AS ID,
                        N_BANKCHECK_CMYID         AS DE_COMPANY_ID,
                        N_BANKCHECK_BANKID        AS DE_BANK_ID,
                        C_BANKCHECK_ACCOUNTNUMBER AS ACCOUNT,
                        C_BANKCHECK_NAMEPAYEE     AS PAYEENAME,
                        D_BANKCHECK_DATE          AS START_DATE,
                        N_BANKCHECK_MONEY         AS PAY_AMOUNT,
                        C_BANKCHECK_CODE          AS DE_CODE,
                        C_BANKCHECK_REMARK        AS REMARK
                   FROM yx_bankcheck) UNION
                (SELECT 3                        AS TYPE,
                        N_TFCHEQUE_ID            AS ID,
                        N_TFCHEQUE_DRAWERCMPID   AS DE_COMPANY_ID,
                        N_TFCHEQUE_DRAWERBANKID  AS DE_BANK_ID,
                        C_TFCHEQUE_DRAWERACCOUNT AS ACCOUNT,
                        C_TFCHEQUE_PAYEENAME     AS PAYEENAME,
                        D_TFCHEQUE_STARTDATE     AS START_DATE,
                        N_TFCHEQUE_INVOICEVALUE  AS PAY_AMOUNT,
                        C_TFCHEQUE_CODE          AS DE_CODE,
                        C_TFCHEQUE_REMARK        AS REMARK
                   FROM YX_TRANSFERCHEQUE) UNION
                (SELECT 4                          AS TYPE,
                        N_CASHCHEQUE_ID            AS ID,
                        N_CASHCHEQUE_DRAWERCMPID   AS DE_COMPANY_ID,
                        N_CASHCHEQUE_DRAWERBANKID  AS DE_BANK_ID,
                        C_CASHCHEQUE_DRAWERACCOUNT AS ACCOUNT,
                        C_CASHCHEQUE_PAYEENAME     AS PAYEENAME,
                        D_CASHCHEQUE_STARTDATE     AS START_DATE,
                        N_CASHCHEQUE_INVOICEVALUE  AS PAY_AMOUNT,
                        C_CASHCHEQUE_CODE          AS DE_CODE,
                        C_CASHCHEQUE_REMARK        AS REMARK
                   FROM yx_cashcheque)) T1
          LEFT JOIN YX_BILLSLEDGERALL T2
            ON T1.TYPE = T2.N_TYPE
           AND T1.ID = T2.N_BILL_ID
          LEFT JOIN SYS_USER T3
            ON T3.USER_ID = T2.N_DRAWERUSERID
          LEFT JOIN SYS_COMPANY CMY
            ON T1.DE_COMPANY_ID = CMY.CMY_ID
          LEFT JOIN SYS_BANK BANK
            ON T1.DE_BANK_ID = BANK.N_ID
          LEFT JOIN YX_ACCOUNT ACT
            ON T1.ACCOUNT=ACT.ACCOUNTNO
         where ACT.COMPANY_ID=CMY.CMY_ID
         AND ACT.N_BANK_ID=BANK.N_ID
         AND ACT.ACCOUNTTYPE = 1 ");

            if (!string.IsNullOrEmpty(whereStr))
            {
                sql += whereStr;
            }

            sql += @" ) TT";
            if (startIndex >= 2)
            {
                sql += " WHERE TT.r BETWEEN (" + startIndex + "-1)*" + endIndex + "+1 AND " + startIndex + "*" + endIndex + "";
            }
            else
            {
                sql += " WHERE TT.r BETWEEN (" + startIndex + "-1)*" + endIndex + " AND " + startIndex + "*" + endIndex + "";
            }
            return Query(sql, "", "GetListByPage", "查询队列", "");
        }

        public DataTable GetListByPage2(string whereStr, string orderby, int startIndex, int endIndex)
        {
            string sql = string.Format(@"SELECT R,TYPE,
       ID,
       DE_COMPANY_ID,
       DE_BANK_ID,
       N_ID,
       N_TYPE,
       N_DRAWERUSERID,
       N_BILL_ID,
       CMY_NAME,
       C_NAME,
       ACCOUNT,
       --C_PAYEECMYNAME,
       C_PAYEEBANKNAME,
       C_PAYEEACCOUNT,
       TYPENAME,
       to_char(D_PURCHASEDATE, 'yyyy-mm-dd') D_PURCHASEDATE,
       DE_CODE,
       COUNT(DE_CODE) FS_NUMBER,
       to_char(START_DATE, 'yyyy-mm-dd') START_DATE,
       N_TERMOFBILL,
       to_char(D_ENDDATE, 'yyyy-mm-dd') D_ENDDATE,
       DE_CODE,
       C_PAYEECMYNAME,
       C_PROJECTNAME,
       C_PROJECTCODE,
       PAY_AMOUNT,
       USER_NAME,
       to_char(D_COLLECTTICKETSTIME, 'yyyy-mm-dd') D_COLLECTTICKETSTIME,
       PAYEENAME,
       C_PAYEENUMBER,
       to_char(D_ACCEPTANCETIME, 'yyyy-mm-dd') D_ACCEPTANCETIME,
       C_DRAWEENAME,
       REMARK
  FROM (SELECT ROW_NUMBER() OVER(ORDER BY " + orderby + @") as r,
               CMY.CMY_NAME AS CMY_NAME,
               BANK.C_NAME AS C_NAME,
               DECODE(T1.TYPE,
                      1,
                      '商业汇票',
                      2,
                      '银行本票',
                      3,
                      '转账支票',
                      4,
                      '现金支票') as TYPENAME,
               T1.*,
               T2.*,
               T3.USER_NAME AS USER_NAME
          FROM ((SELECT 1                         AS TYPE,
                        N_TRADEBILL_ID            AS ID,
                        N_TRADEBILL_DRAWERCMYID   AS DE_COMPANY_ID,
                        N_TRADEBILL_DRAWERBANKID  AS DE_BANK_ID,
                        C_TRADEBILL_DRAWERACCOUNT AS ACCOUNT,
                        C_TRADEBILL_PAYEENAME     AS PAYEENAME,
                        D_TRADEBILL_STARTDATE     AS START_DATE,
                        N_TRADEBILL_INVOICEVALUE  AS PAY_AMOUNT,
                        C_TRADEBILL_CODE          AS DE_CODE,
                        C_TRADEBILL_REMARK        AS REMARK
                   FROM yx_tradebill) UNION
                (SELECT 2                         AS TYPE,
                        N_BANKCHECK_ID            AS ID,
                        N_BANKCHECK_CMYID         AS DE_COMPANY_ID,
                        N_BANKCHECK_BANKID        AS DE_BANK_ID,
                        C_BANKCHECK_ACCOUNTNUMBER AS ACCOUNT,
                        C_BANKCHECK_NAMEPAYEE     AS PAYEENAME,
                        D_BANKCHECK_DATE          AS START_DATE,
                        N_BANKCHECK_MONEY         AS PAY_AMOUNT,
                        C_BANKCHECK_CODE          AS DE_CODE,
                        C_BANKCHECK_REMARK        AS REMARK
                   FROM yx_bankcheck) UNION
                (SELECT 3                        AS TYPE,
                        N_TFCHEQUE_ID            AS ID,
                        N_TFCHEQUE_DRAWERCMPID   AS DE_COMPANY_ID,
                        N_TFCHEQUE_DRAWERBANKID  AS DE_BANK_ID,
                        C_TFCHEQUE_DRAWERACCOUNT AS ACCOUNT,
                        C_TFCHEQUE_PAYEENAME     AS PAYEENAME,
                        D_TFCHEQUE_STARTDATE     AS START_DATE,
                        N_TFCHEQUE_INVOICEVALUE  AS PAY_AMOUNT,
                        C_TFCHEQUE_CODE          AS DE_CODE,
                        C_TFCHEQUE_REMARK        AS REMARK
                   FROM YX_TRANSFERCHEQUE) UNION
                (SELECT 4                          AS TYPE,
                        N_CASHCHEQUE_ID            AS ID,
                        N_CASHCHEQUE_DRAWERCMPID   AS DE_COMPANY_ID,
                        N_CASHCHEQUE_DRAWERBANKID  AS DE_BANK_ID,
                        C_CASHCHEQUE_DRAWERACCOUNT AS ACCOUNT,
                        C_CASHCHEQUE_PAYEENAME     AS PAYEENAME,
                        D_CASHCHEQUE_STARTDATE     AS START_DATE,
                        N_CASHCHEQUE_INVOICEVALUE  AS PAY_AMOUNT,
                        C_CASHCHEQUE_CODE          AS DE_CODE,
                        C_CASHCHEQUE_REMARK        AS REMARK
                   FROM yx_cashcheque)) T1
          LEFT JOIN YX_BILLSLEDGERALL T2
            ON T1.TYPE = T2.N_TYPE
           AND T1.ID = T2.N_BILL_ID
          LEFT JOIN SYS_USER T3
            ON T3.USER_ID = T2.N_DRAWERUSERID
          LEFT JOIN SYS_COMPANY CMY
            ON T1.DE_COMPANY_ID = CMY.CMY_ID
          LEFT JOIN SYS_BANK BANK
            ON T1.DE_BANK_ID = BANK.N_ID
          LEFT JOIN YX_ACCOUNT ACT
            ON T1.ACCOUNT = ACT.ACCOUNTNO
         where /*ACT.COMPANY_ID = CMY.CMY_ID
           AND */ACT.N_BANK_ID = BANK.N_ID
           AND ACT.ACCOUNTTYPE = 1
           AND T2.N_STATE=1 ");

            if (!string.IsNullOrEmpty(whereStr))
            {
                sql += whereStr;
            }

            sql += @" ) TT";
            if (startIndex >= 2)
            {
                sql += " WHERE TT.r BETWEEN (" + startIndex + "-1)*" + endIndex + "+1 AND " + startIndex + "*" + endIndex + "";
            }
            else
            {
                sql += " WHERE TT.r BETWEEN (" + startIndex + "-1)*" + endIndex + " AND " + startIndex + "*" + endIndex + "";
            }
            sql += @" group by R,TYPE,
          ID,
          DE_COMPANY_ID,
          DE_BANK_ID,
          N_ID,
          N_TYPE,
          N_DRAWERUSERID,
          N_BILL_ID,
          D_PURCHASEDATE,
          CMY_NAME,
          C_NAME,
          ACCOUNT,
          C_PAYEEBANKNAME,
          C_PAYEEACCOUNT,
          TYPENAME,
          START_DATE,
          N_TERMOFBILL,
          D_ENDDATE,
          DE_CODE,
          C_PAYEECMYNAME,
          C_PROJECTNAME,
          C_PROJECTCODE,
          PAY_AMOUNT,
          USER_NAME,
          D_COLLECTTICKETSTIME,
          PAYEENAME,
          C_PAYEENUMBER,
          D_ACCEPTANCETIME,
          C_DRAWEENAME,
          REMARK";
            return Query(sql, "", "GetListByPage", "查询队列", "");
        }

        public int GetRecordCount(string whereStr)
        {
            string sql = string.Format(@"SELECT COUNT(*)
  FROM (SELECT
               CMY.CMY_NAME AS CMY_NAME,
               BANK.C_NAME AS C_NAME,
               DECODE(T1.TYPE,
                      1,
                      '商业汇票',
                      2,
                      '银行本票',
                      3,
                      '转账支票',
                      4,
                      '现金支票') as TYPENAME,
               T1.*,
               T2.*,
               T3.USER_NAME AS USER_NAME
          FROM ((SELECT 1                         AS TYPE,
                        N_TRADEBILL_ID            AS ID,
                        N_TRADEBILL_DRAWERCMYID   AS DE_COMPANY_ID,
                        N_TRADEBILL_DRAWERBANKID  AS DE_BANK_ID,
                        C_TRADEBILL_DRAWERACCOUNT AS ACCOUNT,
                        C_TRADEBILL_PAYEENAME     AS PAYEENAME,
                        D_TRADEBILL_STARTDATE     AS START_DATE,
                        N_TRADEBILL_INVOICEVALUE  AS PAY_AMOUNT,
                        C_TRADEBILL_CODE          AS DE_CODE,
                        C_TRADEBILL_REMARK        AS REMARK
                   FROM yx_tradebill) UNION
                (SELECT 2                         AS TYPE,
                        N_BANKCHECK_ID            AS ID,
                        N_BANKCHECK_CMYID         AS DE_COMPANY_ID,
                        N_BANKCHECK_BANKID        AS DE_BANK_ID,
                        C_BANKCHECK_ACCOUNTNUMBER AS ACCOUNT,
                        C_BANKCHECK_NAMEPAYEE     AS PAYEENAME,
                        D_BANKCHECK_DATE          AS START_DATE,
                        N_BANKCHECK_MONEY         AS PAY_AMOUNT,
                        C_BANKCHECK_CODE          AS DE_CODE,
                        C_BANKCHECK_REMARK        AS REMARK
                   FROM yx_bankcheck) UNION
                (SELECT 3                        AS TYPE,
                        N_TFCHEQUE_ID            AS ID,
                        N_TFCHEQUE_DRAWERCMPID   AS DE_COMPANY_ID,
                        N_TFCHEQUE_DRAWERBANKID  AS DE_BANK_ID,
                        C_TFCHEQUE_DRAWERACCOUNT AS ACCOUNT,
                        C_TFCHEQUE_PAYEENAME     AS PAYEENAME,
                        D_TFCHEQUE_STARTDATE     AS START_DATE,
                        N_TFCHEQUE_INVOICEVALUE  AS PAY_AMOUNT,
                        C_TFCHEQUE_CODE          AS DE_CODE,
                        C_TFCHEQUE_REMARK        AS REMARK
                   FROM YX_TRANSFERCHEQUE) UNION
                (SELECT 4                          AS TYPE,
                        N_CASHCHEQUE_ID            AS ID,
                        N_CASHCHEQUE_DRAWERCMPID   AS DE_COMPANY_ID,
                        N_CASHCHEQUE_DRAWERBANKID  AS DE_BANK_ID,
                        C_CASHCHEQUE_DRAWERACCOUNT AS ACCOUNT,
                        C_CASHCHEQUE_PAYEENAME     AS PAYEENAME,
                        D_CASHCHEQUE_STARTDATE     AS START_DATE,
                        N_CASHCHEQUE_INVOICEVALUE  AS PAY_AMOUNT,
                        C_CASHCHEQUE_CODE          AS DE_CODE,
                        C_CASHCHEQUE_REMARK        AS REMARK
                   FROM yx_cashcheque)) T1
          LEFT JOIN YX_BILLSLEDGERALL T2
            ON T1.TYPE = T2.N_TYPE
           AND T1.ID = T2.N_BILL_ID
          LEFT JOIN SYS_USER T3
            ON T3.USER_ID = T2.N_DRAWERUSERID
          LEFT JOIN SYS_COMPANY CMY
            ON T1.DE_COMPANY_ID = CMY.CMY_ID
          LEFT JOIN SYS_BANK BANK
            ON T1.DE_BANK_ID = BANK.N_ID
          LEFT JOIN YX_ACCOUNT ACT
            ON T1.ACCOUNT = ACT.ACCOUNTNO
         where /*ACT.COMPANY_ID = CMY.CMY_ID
           AND */ACT.N_BANK_ID = BANK.N_ID
           AND ACT.ACCOUNTTYPE = 1
           AND T2.N_STATE=1 ");

            if (!string.IsNullOrEmpty(whereStr))
            {
                sql += whereStr;
            }

            sql += @" ) TT";

            int count = GetCount(sql);

            return count;
        }

        /// <summary>
        /// 根据编号查询银行汇票明细
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public YX_BillsLedger SelectById(int id, int type)
        {
            var sql = "SELECT * FROM YX_BILLSLEDGERALL T1 WHERE T1.N_TYPE=" + type + " AND T1.N_BILL_ID=" + id;
            var dt = Query(sql);
            if (dt == null || dt.Rows.Count == 0)
            {
                return null;
            }
            if (dt.Rows.Count > 1)
            {
                throw new Exception("数据异常");
            }

            var entity = new YX_BillsLedger();
            var row = dt.Rows[0];

            entity.D_PURCHASEDATE = row["D_PURCHASEDATE"] == DBNull.Value ? Convert.ToDateTime(("1900-01-01 00:00:00").DateFormat("yyyy-MM-dd hh:mm:ss")) : Convert.ToDateTime(row["D_PURCHASEDATE"]);
            entity.C_DRAWEENAME = Convert.ToString(row["C_DRAWEENAME"]);
            entity.C_PAYEEACCOUNT = Convert.ToString(row["C_PAYEEACCOUNT"]);
            entity.C_PAYEEBANKNAME = Convert.ToString(row["C_PAYEEBANKNAME"]);
            entity.C_PAYEECMYNAME = Convert.ToString(row["C_PAYEECMYNAME"]);
            entity.C_PAYEENUMBER = Convert.ToString(row["C_PAYEENUMBER"]);
            entity.C_PROJECTCODE = Convert.ToString(row["C_PROJECTCODE"]);
            entity.C_PROJECTNAME = Convert.ToString(row["C_PROJECTNAME"]);
            entity.D_ACCEPTANCETIME = Convert.ToDateTime(row["D_ACCEPTANCETIME"]);
            entity.D_COLLECTTICKETSTIME = Convert.ToDateTime(row["D_COLLECTTICKETSTIME"]);
            entity.D_ENDDATE = Convert.ToDateTime(row["D_ENDDATE"]);
            entity.N_BILL_ID = Convert.ToInt32(row["N_BILL_ID"]);
            entity.N_ID = Convert.ToInt32(row["N_ID"]);
            entity.N_DRAWERUSERID = Convert.ToInt32(row["N_DRAWERUSERID"]);
            entity.N_IFOFFER = Convert.ToInt32(row["N_IFOFFER"]);
            entity.N_TERMOFBILL = Convert.ToInt32(row["N_TERMOFBILL"]);
            entity.N_TYPE = Convert.ToInt32(row["N_TYPE"]);
            entity.N_PAYTYPE = Convert.ToInt32(row["N_PAYTYPE"]);
            return entity;
        }

        public YX_BillsLedger SelectById(int id, int type, out IYX_Bill_Base billBase)
        {
            billBase = null;
            switch (type)
            {
                case 1:
                    billBase = new YX_TradeBillBLL().SelectById(id.ToString());
                    break;

                case 2:
                    billBase = new YX_BankCheckBLL().SelectById(id.ToString());
                    break;

                case 3:
                    billBase = new YX_TransferChequeBLL().SelectById(id.ToString());
                    break;

                case 4:
                    billBase = new YX_CashChequeBLL().SelectById(id.ToString());
                    break;

                default:
                    throw new Exception("Type异常");
            }
            var entity = SelectById(id, type);

            if (entity == null)
            {
                return null;
            }

            return entity;
        }

        public bool UPDATE(YX_BillsLedger model, string operName)
        {
            string sql = string.Format(@"update yx_billsledgerall
   set n_type               = {0},
       n_draweruserid       = {1},
       c_draweename         = '{2}',
       c_payeecmyname       = '{3}',
       c_payeebankname      = '{4}',
       c_payeeaccount       = '{5}',
       c_payeenumber        = '{6}',
       d_enddate            = TO_DATE('{7}','YYYY-MM-DD HH24:MI:SS'),
       n_termofbill         = {8},
       d_acceptancetime     = TO_DATE('{9}','YYYY-MM-DD HH24:MI:SS'),
       d_collectticketstime = TO_DATE('{10}','YYYY-MM-DD HH24:MI:SS'),
       c_projectname        = '{11}',
       c_projectcode        = '{12}',
       n_ifoffer            = {13},
       n_bill_id            = {14},
       N_PAYTYPE            = {15},
       D_PURCHASEDATE       = TO_DATE('{16}','YYYY-MM-DD HH24:MI:SS')
 where n_type = {17} and n_bill_id={18}
", model.N_TYPE, model.N_DRAWERUSERID, model.C_DRAWEENAME, model.C_PAYEECMYNAME, model.C_PAYEEBANKNAME, model.C_PAYEEACCOUNT, model.C_PAYEENUMBER, model.D_ENDDATE, model.N_TERMOFBILL, model.D_ACCEPTANCETIME, model.D_COLLECTTICKETSTIME, model.C_PROJECTNAME, model.C_PROJECTCODE, model.N_IFOFFER, model.N_BILL_ID, model.N_PAYTYPE, model.D_PURCHASEDATE, model.N_TYPE, model.N_BILL_ID);
            int count = NoQuery(sql, operName);
            bool istrue = false;
            if (count > 0)
            {
                istrue = true;
            }
            return istrue;
        }

        public bool Insert(YX_BillsLedger entity, string operName)
        {
            entity.N_ID = GetSequence("SEQ_N_BBLEDGERALLNEW_ID");
            string sql = string.Format(@"insert into yx_billsledgerall
  (n_id,
   n_type,
   n_draweruserid,
   c_draweename,
   c_payeecmyname,
   c_payeebankname,
   c_payeeaccount,
   c_payeenumber,
   d_enddate,
   n_termofbill,
   d_acceptancetime,
   d_collectticketstime,
   c_projectname,
   c_projectcode,
   n_ifoffer,
   n_bill_id,N_PAYTYPE,D_PURCHASEDATE)
values
  ({0},
   {1},
   {2},
   '{3}',
   '{4}',
   '{5}',
   '{6}',
   '{7}',
   TO_DATE('{8}','YYYY-MM-DD HH24:MI:SS'),
   {9},
   TO_DATE('{10}','YYYY-MM-DD HH24:MI:SS'),
   TO_DATE('{11}','YYYY-MM-DD HH24:MI:SS'),
   '{12}',
   '{13}',
   {14},{15},{16},
    TO_DATE('{17}','YYYY-MM-DD HH24:MI:SS'))", entity.N_ID, entity.N_TYPE, entity.N_DRAWERUSERID, entity.C_DRAWEENAME, entity.C_PAYEECMYNAME, entity.C_PAYEEBANKNAME, entity.C_PAYEEACCOUNT, entity.C_PAYEENUMBER, entity.D_ENDDATE, entity.N_TERMOFBILL, entity.D_ACCEPTANCETIME, entity.D_COLLECTTICKETSTIME, entity.C_PROJECTNAME, entity.C_PROJECTCODE, entity.N_IFOFFER, entity.N_BILL_ID, entity.N_PAYTYPE, entity.D_PURCHASEDATE);
            int count = NoQuery(sql, operName);
            bool istrue = false;
            if (count > 0)
            {
                istrue = true;
            }
            return istrue;
        }

        #region 删除

        /// <summary>
        /// 删除一个
        /// </summary>
        /// <param name="table"></param>
        /// <param name="col"></param>
        /// <param name="operName"></param>
        /// <returns></returns>
        public bool Delete(string table, string col, string operName)
        {
            var sql = string.Format("DELETE FROM QS_SEQUENCES WHERE C_TABLE_NAME = '{0}' AND C_COL_NAME = '{1}'", Transference(table.ToUpper()), Transference(col.ToUpper()));
            if (NoQuery(sql, operName) > 0)
            {
                return true;
            }
            return false;
        }

        public int DeleteRange(List<decimal> ids, string operatename)
        {
            if (ids.Count == 0)
            {
                return 0;
            }
            if (ids.Count == 1)
            {
                return Delete(ids[0], operatename);
            }
            var idsStr = "";
            for (int i = 1; i <= ids.Count; i++)
            {
                idsStr += ids[i - 1].ToString().Trim();
                if (i != ids.Count)
                {
                    idsStr += ",";
                }
            }
            return DeleteRange(idsStr, operatename);
        }

        /// <summary>
        /// 删除一条意见处理
        /// </summary>
        /// <param name="id">ID</param>
        /// <param name="operatename">用户名称</param>
        /// <returns></returns>
        public int Delete(decimal id, string operatename)
        {
            var sql = string.Format(@"DELETE FROM YX_BILLSLEDGERALL WHERE N_ID IN({0})", id);
            return NoQuery(sql, operatename);
        }

        /// <summary>
        /// 批量删除意见处理
        /// </summary>
        /// <param name="ids"></param>
        /// <param name="operatename">用户名称</param>
        /// <returns></returns>
        public int DeleteRange(string ids, string operatename)
        {
            if (string.IsNullOrEmpty(ids))
            {
                return 0;
            }
            //var sql = string.Format(@"DELETE FROM SYS_OPINION WHERE N_OPIN_ID IN ({0})", ids);
            var sql = string.Format(@"UPDATE SYS_OPINION SET N_ISDEL = 1 WHERE N_OPIN_ID IN ({0})", ids);
            return NoQuery(sql, operatename);
        }

        #endregion 删除
    }
}